//
//  JBaseViewController.m
//  HeadIndustry
//
//  Created by jun on 2017/8/24.
//  Copyright © 2017年 jun. All rights reserved.
//

#import "JBaseViewController.h"

@interface JBaseViewController ()
{
    BOOL _isHiddenNavigationBarWhenDisappear;//记录当页面消失时是否需要隐藏系统导航
    BOOL _isHasTabBarController;//是否含有tabbar
    BOOL _isHasNavitationController;//是否含有导航
}

@end

@implementation JBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)InitUI {
    
    _isHasNavitationController = self.navigationController?YES:NO;

    if (_isHasNavitationController == YES) {
        if (self.navigationController.navigationBarHidden == YES) {
//            _isHiddenNavigationBarWhenDisappear = NO;
        } else {
            self.navigationController.navigationBarHidden = YES;
//            _isHiddenNavigationBarWhenDisappear = YES;
        }
    }
    
    //将navigationController隐藏起来
    self.navigationController.navigationBarHidden = YES;
    
    _navigationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), NavigationBar_HEIGHT)];
    [self.view addSubview:_navigationView];

    _navigationImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), NavigationBar_HEIGHT+20)];
    //    _navigationImgView.image = [UIImage imageNamed:@"bg03"];
    _navigationView.backgroundColor = kRGBColor(255, 255, 255);
    [self.navigationView addSubview:self.navigationImgView];
    
    //        [self.view setBackgroundColor:RGBCOLOR(238, 238, 238)];
    
    // 设置左按钮
    self.leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [self.leftButton setImage:[UIImage imageNamed:backBtnImg] forState:UIControlStateNormal];
    [self.leftButton setFrame:CGRectMake(8, NAVIGATION_HEIGHT_SUBVIEWS_Y+5, 50, 30)];
    [self.leftButton addTarget:self
                        action:@selector(leftButtonClick:)
              forControlEvents:UIControlEventTouchUpInside];
    [self.leftButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    [self.leftButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [_navigationView addSubview:self.leftButton];
    
    // 设置右按钮
    self.rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //    [self.rightButton setImage:[UIImage imageNamed:@"btn_function"] forState:UIControlStateNormal];
    [self.rightButton setFrame:CGRectMake(kWindowW-50-5, NAVIGATION_HEIGHT_SUBVIEWS_Y+5, 50, 30)];
    [self.rightButton addTarget:self
                         action:@selector(rightButtonClick:)
               forControlEvents:UIControlEventTouchUpInside];
    [self.rightButton setTitleColor:kRGBColor(255, 255, 255) forState:UIControlStateNormal];
    [self.rightButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [self.rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_navigationView addSubview:self.rightButton];
    
    _rightButton.hidden = YES; //默认为隐藏
    _leftButton.hidden = YES;
    
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(56, NAVIGATION_HEIGHT_SUBVIEWS_Y, kWindowW - 60 * 2, 44)];
    _titleLabel.backgroundColor = [UIColor clearColor];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    //    _titleLabel.textColor = [UIColor whiteColor];
    _titleLabel.font = [UIFont systemFontOfSize:16];
    [_titleLabel setText:_controllerTitle];
    [_navigationView addSubview:_titleLabel];
    
    _labLine = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(_navigationView.frame)-1, _navigationView.frame.size.width, 1)];
    _labLine.backgroundColor = kRGBColor(220, 220, 220);
    
    [_navigationView addSubview:_labLine];
    
    _contentView = [[UIView alloc] initWithFrame:CGRectMake(0, NavigationBar_HEIGHT, kWindowW, kWindowH-NavigationBar_HEIGHT)];
    [_contentView setBackgroundColor:kRGBColor(238, 238, 238)];
    [self.view addSubview:_contentView];
    
//    UISwipeGestureRecognizer *swipeGestrue = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestrue:)];
//    [_contentView addGestureRecognizer:swipeGestrue];
}
- (void)setControllerTitle:(NSString *)controllerTitle {
    _controllerTitle = controllerTitle;
    _titleLabel.text = controllerTitle;
}

/// 滑动手势 退出
- (void)swipeGestrue:(UISwipeGestureRecognizer *)gestrue
{
    if (self.leftButton.hidden == NO) {
        //判断是左或者右
        switch (gestrue.direction){
            case UISwipeGestureRecognizerDirectionRight:
                
                [self.navigationController popViewControllerAnimated:YES];
                
                break;
                
            default:
                break;
        }
    }
}

- (void)leftButtonClick:(UIButton *)leftButton {
    [SVProgressHUD dismiss];
}

- (void)rightButtonClick:(UIButton *)rightButton {
    
}

@end
